define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_transfer_publish(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {  "goods_id": "001","prodect_id":"001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_cat_list(result) {
			if(false){
				result = '{"success":true,"msg":"","result":{"custom_cat":[{"custom_cat_id":1,"store_id":1,"parent_id":1,"is_leaf":false,"cat_name":"大分类","disabled":false,"p_order":1,"goods_count":10,"child_count":2},{"custom_cat_id":2,"store_id":2,"parent_id":1,"is_leaf":true,"cat_name":"中分类","disabled":false,"p_order":2,"goods_count":10,"child_count":1}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		//获取
        function get_data_gproperty_getlist(result){
            if(false) {
                result = '{"success": true,"msg": "","result": {"property":[' +
                    '{"id":"001","name":"颜色"},' +
                    '{"id":"002","name":"重量"}' +
                    ']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }


		//返回信息
		return {
			transfer_publish: function(goods_id,goods_state,transfer_type,name,property,bn,keywords,brief,image,price,market_price,is_marketable,product_bn,weight,cat_list_id,callback) {
				var params = new Object();
				params.goods_id = goods_id;
				params.goods_state = goods_state;
				params.transfer_type = transfer_type;
				params.name = name;
				params.property = property;
				params.bn = bn;
				params.keywords = keywords;
				params.brief = brief;
				params.image = image;
				params.price = price;
				params.market_price = market_price;
				params.is_marketable = is_marketable;
				params.product_bn = product_bn
				params.weight = weight;
				params.cat_list_id = cat_list_id;
				params = JSON.stringify(params);
				console.log(params)

				Http.post({
					method: 'goods.transfer.edit',
					updateParams:params
				}, function(result) {
					if(callback)
						callback(get_data_transfer_publish(result));
				}, function(e) {

				}, function() {

				})
			},

			get_catlist: function(callback) {
				Http.post({
					method: 'goods.cat.list.get'
				}, function(result) {
					if(callback)
						callback(get_cat_list(result).result);
				}, function(e) {

				}, function() {

				})
			},
			//商品属性
            getProperty: function(custom_cat_id, callback) {
                Http.post({
                        method: 'goods.property.getlist',
                        custom_cat_id: custom_cat_id,//转让商品该参数为空即可
                        kind:6
                    },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(get_data_gproperty_getlist(result).result);
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    });
            },

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Transfer_publish", factory);
});